<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/jquery-3.3.1.js"></script>
    <style>
        *{
            margin: 0px;
            padding: 0px;
        }
        body > div {
            overflow: hidden;
            width: 600px;
            height: 300px;
            margin: 0px auto;
            position: relative;
        }
        .transImg{
            width: 600px;
            height: 300px;
            margin: 0px auto;
            position: absolute;
        }
    </style>
</head>
<body>
    <div>
        <div class="transImg">
            
        </div>
    </div>
    <script>
        class TransImg{
            constructor(ele,arr){
                this.ele = ele;
                this.arr = arr ;
                this.page = 1 ;
                this.renderDom();
                this.autoPlay();
            }
            renderDom(){
                this.ele.innerHTML = '' ;
                let _that = this ; 
                this.arr.forEach((item,key)=>{
                    let imgEle = document.createElement("img") ;
                    $(imgEle).css({
                        position:'absolute',
                        width:parseInt($(_that.ele).width()),
                        height:parseInt($(_that.ele).height()),
                        left:key * parseInt($(_that.ele).width())
                    });
                    $(imgEle)[0].src = `${item}`;
                    _that.ele.appendChild(imgEle);
                });
            }
            autoPlay(){
                let _that = this ; 
                setInterval(() => {
                    $(_that.ele).animate({left: `-${_that.page * parseInt($(_that.ele).width())}px`}, "slow",function(){
                        _that.page ++ ;
                        if( _that.page % 5 == 0 ){
                            _that.page = 1 ;
                            _that.ele.style.left = "-600px";
                        }
                        console.log(`-${_that.page * parseInt($(_that.ele).width())}px`);
                    });
                }, 2000);
            }
        }
        let divEle = document.querySelector(".transImg");
        let auto = new TransImg(divEle,["../images/1.jpg","../images/2.jpg","../images/3.jpg","../images/4.jpg","../images/5.jpg"]);
        </script>
</body>
</html>